package com.java.sys.access;

import com.test.scx.PrivilegedFileUtil;

import java.security.AccessControlException;

/**
 * @ClassName: AccessControllerTest
 * @Author: suncx
 * @CreateDate: 2020-04-12 16:44
 * @Description:
 */
public class AccessControllerTest {
    public static void main(String[] args) {

        // 打开系统安全权限检查开关
        System.setSecurityManager(new SecurityManager());

        try {
            String pathName = "C:\\test\\test-path-product-1.txt";
            System.out.println("1=======================" + PrivilegedFileUtil.canRead(pathName));
        }catch (AccessControlException e1) {
            e1.printStackTrace();

        }

        try {
            String pathName = "C:\\test\\test-wtite.txt";
            PrivilegedFileUtil.makeFile(pathName);
            System.out.println("2=======================");
        } catch (AccessControlException e1) {
            e1.printStackTrace();
        }

        try {
            String pathName = "C:\\test\\test-wtite-use-Privileged.txt";
            PrivilegedFileUtil.doPrivilegedAction(pathName);
            System.out.println("3=======================");
        } catch (AccessControlException e1) {
            e1.printStackTrace();
        }

    }

}
